package com.liuhe.collections.test1;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Test2 {
    public static void main(String[] args) {
        //通过概率抽取男 70% 女生 30%
        //创建男女生集合
        ArrayList<String> boys = new ArrayList<>();
        ArrayList<String> girls = new ArrayList<>();
        //添加数据
        Collections.addAll(boys, "b1", "b2", "b3", "b4", "b5");
        Collections.addAll(girls, "g1", "g2", "g3", "g4", "g5");
        ArrayList<Integer> list = new ArrayList<>();
        //添加数据
        Collections.addAll(list, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0);
        //打乱顺序
        Collections.shuffle(list);
        //随机获取
        Random r = new Random();
        int index = r.nextInt(list.size());
        int number = list.get(index);
        //进行判断
        if (number == 1) {
            //抽取男生
            int bIndex = r.nextInt(boys.size());
            System.out.println(boys.get(bIndex));

        } else {
            //抽取女生
            int gIndex = r.nextInt(girls.size());
            System.out.println(girls.get(gIndex));
        }
    }
}
